#include<bits/stdc++.h>
using namespace std;
int T,n,m,V,L,ans1=0,ans2=0;

int main(){

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    cin>>n>>m>>L>>V;
    int a1,a2;

    for(int z=1;z<=T;z++){
        a1=0;
        a2=0;

        int d[n+1],v[n+1],a[n+1],p[m+1];
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        for(int i=1;i<=n;i++){
                if(a[i]==0 && v[i]>V && d[i]<=L){
                    a1+=1;
                    }
        }
        for(int i=1;i<=m;i++){
            for(int j=1;j<=m-i;j++){
                if(p[j]>p[j+1]){
                    swap(p[j],p[j+1]);
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n-i;j++){
                if(d[j]<d[j+1]){
                    swap(d[j],d[j+1]);
                }
            }
        }
        for(int i=1;i<=m;i++){
            if(p[i]<d[i]) a2+=1;
        }
cout<<a1<<" "<<a2<<endl;
    }

    return 0;
}
